package com.lwl.office.dcconverter.element;

import com.lwl.office.webeditor.ParserContext;
import com.lwl.office.webeditor.tools.ConvertUtil;
import lombok.Data;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFStyle;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;

@Data
public class DCHeader extends DCParagraph {
    private int level;

    @Override
    public void parseWord(ParserContext context) {
        XWPFParagraph paragraph = context.createParagraph();
        CTP ctp = paragraph.getCTP();
        XWPFStyle style = context.buildHeaderStyle(((DCHeader) this).getLevel());
        CTPPr ctpPr =ctp.isSetPPr()?ctp.getPPr():ctp.addNewPPr();
        ctpPr.setPStyle(ConvertUtil.ctsOf(style.getStyleId()));
        //子节点解析成word
        for (AbsDCElement child : getChildren()) {
            child.parseWord(context);
        }
    }

    public DCHeader(int level) {
        this.level = level;
    }

    @Override
    public String getTagName() {
        return "h"+level;
    }
}
